﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.DynamicData;
using System.Web.UI;
using System.Collections;

namespace Fatec.ControleEstoque.Attributes.Templates
{
    public class FieldTemplateRowGenerator : IAutoFieldGenerator
    {
        protected MetaTable _table;
        protected String[] _displayColumns;

        public FieldTemplateRowGenerator(MetaTable table)
        {
            _table = table;
        }

        public FieldTemplateRowGenerator(MetaTable table, String[] displayColumns)
        {
            _table = table;
            _displayColumns = displayColumns;
        }

        public ICollection GenerateFields(Control control)
        {
            List<DynamicField> oFields = new List<DynamicField>();

            foreach (var column in _table.Columns)
            {
                // carry on the loop at the next column  
                // if scaffold table is set to false or DenyRead
                if (!column.Scaffold)
                    continue;

                if (_displayColumns != null && !_displayColumns.Contains(column.Name))
                    continue;

                DynamicField f = new DynamicField();

                f.DataField = column.Name;
                oFields.Add(f);
            }
            return oFields;
        }
    }
}